(function (vc) {
    vc.extends({
        data: {
            addHousekeepingFeeConfigRelInfo: {
                configId: '',
                feeName: '',
                hktId: '',
                feeTypeCd: '',
                servId: '',
                servName: '',
                housekeepingFeeTypes: [],
                housekeepingFeeConfigs: [],
                housekeepingTypes: []
            }
        },
        _initMethod: function () {
            $that._listRelAddHousekeepingFeeTypes();
            $that._listRelAddHousekeepingTypes();
        },
        _initEvent: function () {
            vc.on('addHousekeepingFeeConfigRel', 'openAddHousekeepingFeeConfigRelModel', function (_param) {
                $('#addHousekeepingFeeConfigRelModel').modal('show');
                $that.clearaddHousekeepingFeeConfigRelInfo();
                $that.addHousekeepingFeeConfigRelInfo.servId = _param._servId;
                $that.addHousekeepingFeeConfigRelInfo.servName = _param._servName;
            });
        },
        methods: {
            addHousekeepingFeeConfigRelValidate() {
                return vc.validate.validate({
                    addHousekeepingFeeConfigRelInfo: $that.addHousekeepingFeeConfigRelInfo
                }, {
                    
                    'addHousekeepingFeeConfigRelInfo.feeTypeCd': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "费用大类不能为空"
                        }
                    ],
                    'addHousekeepingFeeConfigRelInfo.configId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "费用标准不能为空"
                        }
                    ]
                });
            },
            saveHousekeepingFeeConfigRelInfo: function () {
                if (!$that.addHousekeepingFeeConfigRelValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addHousekeepingFeeConfigRelInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/housekeepingServFee/saveHousekeepingServFee',
                    JSON.stringify($that.addHousekeepingFeeConfigRelInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addHousekeepingFeeConfigRelModel').modal('hide');
                            if ($that.addHousekeepingFeeConfigRelInfo.servId == '') {
                                vc.emit('housekeepingServManage', 'listHousekeepingServ', {});
                            } else {
                                let _serId = $that.addHousekeepingFeeConfigRelInfo.servId;
                                let _servName = $that.addHousekeepingFeeConfigRelInfo.servName;
                                vc.emit('housekeepingServFeeConfigManageRel', 'listHousekeepingServFeeConfigRel', {
                                    _serId,
                                    _servName
                                });
                            }
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            //费用大类
            _listRelAddHousekeepingFeeTypes: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingFeeType/queryHousekeepingFeeType',
                    param,
                    function (json, res) {
                        var _housekeepingFeeTypeManageInfo = JSON.parse(json);
                        $that.addHousekeepingFeeConfigRelInfo.housekeepingFeeTypes = _housekeepingFeeTypeManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //服务类型
            _listRelAddHousekeepingTypes: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        typeCd: 1001,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingType.queryHousekeepingType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.addHousekeepingFeeConfigRelInfo.housekeepingTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //费用明细
            _listRelAddHousekeepingFeeConfigs: function (_feeTypeCd) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId,
                        feeTypeCd: _feeTypeCd
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingFeeConfig/queryHousekeepingFeeConfig',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.addHousekeepingFeeConfigRelInfo.housekeepingFeeConfigs = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            setAddFeeName: function (_configId) {
                $that.addHousekeepingFeeConfigRelInfo.housekeepingFeeConfigs.forEach(item => {
                    if (item.configId == _configId) {
                        $that.addHousekeepingFeeConfigRelInfo.feeName = item.feeName;
                    }
                });
            },
            clearaddHousekeepingFeeConfigRelInfo: function () {
                let _housekeepingFeeTypes = $that.addHousekeepingFeeConfigRelInfo.housekeepingFeeTypes;
                let _housekeepingFeeConfigs = $that.addHousekeepingFeeConfigRelInfo.housekeepingFeeConfigs;
                let _housekeepingTypes = $that.addHousekeepingFeeConfigRelInfo.housekeepingTypes;
                $that.addHousekeepingFeeConfigRelInfo = {
                    configId: '',
                    feeName: '',
                    hktId: '',
                    feeTypeCd: '',
                    servId: '',
                    servName: '',
                    housekeepingFeeTypes: _housekeepingFeeTypes,
                    housekeepingFeeConfigs: _housekeepingFeeConfigs,
                    housekeepingTypes: _housekeepingTypes
                };
            }
        }
    });
})(window.vc);
